var temp = object(tempAbs);
temp.sampleInfos = [];
temp.address = false;
temp.read = function(obj,bn){
	bn.setSampleInfos();
	if (obj && obj.customerCode) {
		bn.setComboBox('customerCode', obj.customerCode);
	}
	$(".second-table .field input").each(function(){
		var id = $(this).attr('id');
		if(id && id.indexOf('sampleType_')<0){
			if($(this).hasClass('easyui-datebox')){
				bn.setDat(id);
			}else{
				var type = $(this).attr('type');
				if(type=='text' || type=='date' || type=='number'){
					bn.setVl(id);
				}
			}
		}
	});
	$(".second-table .field select").each(function(){
		var id = $(this).attr('id');
		bn.setSel(id);
	});
	if(obj.sampleType){
		var sampleTypeArr = obj.sampleType.split(',');
		$("input:checkbox[name^='sampleType_']").each(function(i){
			var id = $(this).attr('name');
			setCkArr(id,sampleTypeArr[i]);
		});
	}
	
	var all = {};
	$(".second-table .group-field").children('input').each(function(){
		var id = $(this).attr('id');
		all[id.split('_')[0]] = 1;
	});
	for(var key in all){
		bn.setCkGrp(key,$("input:checkbox[id^='"+key+"_']").length);
	}
	//处理多选框start
	$(".group-field input").each(function(){
		if($(this).is(":checked")){
			var id = $(this).attr('id');
			var arr = id.split('_');
			bn.obj[arr[0]] = arr[1];
		}
	});
	var multiObj = {};
	$(".multi-field input").each(function(){
		var id = $(this).attr('id');
		var tarr = id.split('_');
		if(tarr.length==2){
			var vArr = multiObj[tarr[0]];
			if(!vArr){
				vArr = [];
			}
			vArr.push(id);
			multiObj[tarr[0]]=vArr;
		}
	});
	for(var key in multiObj){
		if(obj[key]){
			var values = obj[key].split(',');
			for(var i=0;i<values.length;i++){
				$("#"+key+"_"+values[i]).attr('checked',true);
			}
		}
	}
	//处理多选框end
	if(typeof(readExtends)!='undefined'){
		readExtends(obj,bn);
	}
}

temp.save = function(bn){
	bn.getSampleInfos(temp.sampleInfos);
	bn.getComboGrid('customerCode');
	bn.vl('sampleNum');
	$(".second-table .field input").each(function(){
		var id = $(this).attr('id');
		if(id && id.indexOf('sampleType_')<0){
			var type = $(this).attr('type');
			if($(this).hasClass('easyui-datebox')){
				bn.dat(id);
			}else{
				if(type=='text'){
					bn.vl(id);
				}else if(type=='date'){
					bn.vl(id);
				}else if(type=='number'){
					bn.vl(id);
				}
			}
		}
	});
	$(".second-table .field select").each(function(){
		var id = $(this).attr('id');
		bn.sel(id);
	});
	var sampleTypeArr = [];
	var countSampleType = {};
	$("input:checkbox[name^='sampleType_']").each(function(){
		countSampleType[$(this).attr('name')] = 1;
	});
	for(var key in countSampleType){
		var val = ckArr(key);
		if(val){
			sampleTypeArr.push(val);
		}
	}
	bn.obj.sampleType = sampleTypeArr.join(',');
	//处理单选框字段
	$(".group-field input").each(function(){
		if($(this).is(":checked")){
			var id = $(this).attr('id');
			var arr = id.split('_');
			bn.obj[arr[0]] = arr[1];
		}
	});
	//处理多选框start
	var multiObj = {};
	$(".multi-field input").each(function(){
		var id = $(this).attr('id');
		var tarr = id.split('_');
		if(tarr.length==2){
			var vArr = multiObj[tarr[0]];
			if(!vArr){
				vArr = [];
			}
			vArr.push(id);
			multiObj[tarr[0]]=vArr;
		}
	});
	for(var id in multiObj){
		var arr = multiObj[id];
		var value = [];
		for(var i=0;i<arr.length;i++){
			if($("#"+arr[i]).is(":checked")){
				value.push(arr[i].split('_')[1]);
			}
		}
		bn.obj[id] = value.join(',');
	}
	//处理多选框end
	if(typeof(saveExtends)!='undefined'){
		saveExtends(bn);
	}
}
temp.validateAbs = function(m){
	var msg = '';
	if(m) msg += m;
	return msg;
}
//组合复选框变单选框
$(function(){
	var p1 = null;
	var sortIndex = 1;
	$(".sample-type").each(function(index){
		var trArr = $(this).parent().parent().parent().parent().find('tr');
		var tTrArr = [];
		for(var i=0;i<trArr.length;i++){
			tTrArr.push(trArr[i]);
		}
		if(index==0){
			p1 = $(this).parent()[0];
			$(this).children("input:eq(0)").attr('name',"sampleType_"+sortIndex);
		}else{
			if(p1 != $(this).parent()[0] && Math.abs(tTrArr.indexOf(p1.parentNode)-tTrArr.indexOf($(this).parent().parent()[0]))>1){
				sortIndex++;
			}
			p1 = $(this).parent()[0];
			$(this).children("input:eq(0)").attr('name',"sampleType_"+sortIndex);
		}
	});
	var countObj = {};//统计有多少组需要单选的checkbox
	$(".second-table .group-field input").each(function(){
		var name = $(this).attr("name");
		countObj[name] = 1;
	});
	$(".second-table .sample-type input").each(function(){
		var name = $(this).attr("name");
		countObj[name] = 1;
	});
	for(var key in countObj){
		$("input[type=checkbox][name='"+key+"']").click(function(){
			if($(this).is(':checked')){
				if($(this).siblings('input').length>0){
					$(this).siblings('input').attr('checked',false);
				}else{
					$(this).parent('span').siblings().children('input').attr('checked',false);
				}
			}
		});
	}
	$("input:checkbox[id^='product_']").each(function(){
		var id = $(this).attr('id');
		temp.sampleInfos.push({productCode:id.split('_')[1],projectCode:''});
	});
});